package com.ny.demo526;

import java.util.Iterator;
import java.util.Set;

public class TestSet {

        public static void menu() {
            System.out.println("欢迎来到员工信息管理系统");
            System.out.println("0.退出系统");
            System.out.println("1.添加员工");
            System.out.println("2.查询所有的员工");
            System.out.println("3.根据员工姓名查询");
            System.out.println("4.删除员工信息");
            System.out.println("5.根据员工编号查询");
            System.out.println("6.根据员工编号修改年龄");
            System.out.println("请选择你需要进行的操作");
        }

        public void addEmp(Set<Emp> set, Emp emp) {
            set.add(emp);
        }

        public void findAllEmp(Set<Emp> set) {
            for (Emp emp : set) {
                System.out.println(emp);
            }
        }

        public void findEmpName(Set<Emp> set, String name) {
            for (Emp emp : set) {
                if (name.equals(emp.getName())) {
                    System.out.println(emp);
                }
            }
        }

        public void deleteEmpNumber(Set<Emp> set, String number) {
            Iterator<Emp> iterator = set.iterator();
            while (iterator.hasNext()) {
                Emp emp = iterator.next();
                if (number.equals(emp.getNumber())) {
                    iterator.remove();
                    System.out.println(set);
                    break;
                }
            }
        }

        public Emp findEmpNumber(Set<Emp> set, String number) {
            for (Emp emp : set) {
                if (number.equals(emp.getNumber())) {
                    return emp;
                }
            }
            return null;
        }

        public void updateEmpAge(Set<Emp> set, Emp emp) {
            Iterator<Emp> iterator = set.iterator();
            while (iterator.hasNext()) {
                Emp e = iterator.next();
                if (emp.getNumber().equals(e.getNumber())) {
                    iterator.remove();
                    set.add(emp);
                    break;
                }
            }
        }
    }
